package com.lanhao.aot.util;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.FileUtils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.beust.jcommander.internal.Lists;

import cn.hutool.core.util.StrUtil;

public class CPICDataUtil {
	public static void main(String[] args) {
		try {
			String[] fileNameArray = { "20221201.log", "20221207.log", "20221210.log"};
			List<String> mergeList = Lists.newArrayList();
			for (String fileName : fileNameArray) {
				List<String> readLines = FileUtils.readLines(new File("E:\\file\\" + fileName), "UTF-8");
				mergeList.addAll(readLines);
			}
			System.out.println(mergeList.size());
			FileUtils.writeLines(new File("E:\\file\\total.log"), mergeList);
			
			List<String> requestList = Lists.newArrayList();
			List<String> readLines = FileUtils.readLines(new File("E:\\file\\total.log"), "UTF-8");
			for (String line : readLines) {
				String request = line.substring(line.lastIndexOf("收到太保的同步订单并获取标签接口，解密后decryptRequest="));
				request = request.replaceAll("收到太保的同步订单并获取标签接口，解密后decryptRequest=", "");
				JSONObject requestObject = JSON.parseObject(request);
				String bussinessNo = requestObject.getString("businessNo");
				JSONObject extendInfo = requestObject.getJSONObject("extendInfo");
				String currencyRate = extendInfo.getString("currencyRate");
				String applyAmount = extendInfo.getString("applyAmount");
				System.out.println(
						"bussinessNo=" + bussinessNo + ",currencyRate=" + currencyRate + ",applyAmount=" + applyAmount);
				String sqlTpl = "update order_item_sku_info t set t.currency_rate = '{}', t.apply_amount = '{}' where t.remark = '{}';";
				
				String sql = StrUtil.format(sqlTpl, currencyRate, StringUtils.isNotBlank(applyAmount) ? applyAmount : "0.00", bussinessNo);
				requestList.add(sql);
			}
			FileUtils.writeLines(new File("E:\\file\\sql.log"), requestList);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
